import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class RedisString {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");

        try (Jedis jedis = jedisPool.getResource()) {
//            testMgetAndMset(jedis);

//            testGetrangeAndSetrange(jedis);

//            testAppend(jedis);

            testIncr(jedis);
        }
    }


    public static void testIncr(Jedis jedis) {
        jedis.flushAll();

        jedis.set("key1", "100");
        System.out.println(jedis.incr("key1"));

        System.out.println(jedis.incrBy("key1", 100));

        System.out.println(jedis.decr("key1"));

        System.out.println(jedis.decrBy("key1", 100));
    }

    public static void testAppend(Jedis jedis) {
        jedis.flushAll();

        jedis.set("key1", "zzzzz");

        jedis.append("key1", "aaaa");

        System.out.println(jedis.get("key1"));

        jedis.append("key2", "cccc");
        System.out.println(jedis.get("key2"));
    }

    public static void testGetrangeAndSetrange(Jedis jedis) {
        jedis.flushAll();

        jedis.set("key1", "sagdhgafadfbgdfsd");
        System.out.println(jedis.getrange("key1", 0, -1));

        jedis.setrange("key1", 2, "zzzzzzzzzzzzzzzzzzzzzzz");
        System.out.println(jedis.get("key1"));
    }

    public static void testMgetAndMset(Jedis jedis) {
        jedis.flushAll();

        jedis.mset("key1", "111", "key2", "222");

        List<String> values = jedis.mget("key1", "key2", "key3");
        System.out.println(values);
    }
}
